//
//  HBTaskCell.m
//  HeartBeat
//
//  Created by karong on 2023/8/29.
//

#import "HBTaskCell.h"
#import "HBTaskItemCell.h"
#import "HBTaskModel.h"

@interface HBTaskCell () <WSTaskItemCellDelegate>
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UICollectionView *listView;
@property (nonatomic, strong) NSArray * dataArray;
@end
@implementation HBTaskCell
- (void)setDataWithObject:(id)object type:(NSInteger)type {
    self.titleLabel.text = type?WSLocalized(@"新手福利"):WSLocalized(@"每日福利");
    self.dataArray = object;
    [self.listView reloadData];
}

#pragma mark UICollectionViewDelegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HBTaskItemCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HBTaskItemCell" forIndexPath:indexPath];
    cell.delegate = self;
    [cell setDataWithObject:self.dataArray[indexPath.row]];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGSize size = CGSizeZero;
    size.width = HBScreenWidth - 12 - 12;
    size.height = 77;
    
    return size;
}

#pragma mark WSTaskItemCellDelegate
- (void)taskItemCellAction:(UICollectionViewCell *)cell type:(NSInteger)type {
    NSIndexPath * indexPath = [self.listView indexPathForCell:cell];
    HBTaskModel * task = self.dataArray[indexPath.row];
    if (task.task_status == 0) {
        //跳轉
        if ([self.delegate respondsToSelector:@selector(taskCellTurnActionWithType:)]) {
            [self.delegate taskCellTurnActionWithType:type];
        }
    }
    else if (task.task_status == 1) {
        //領取
        if ([self.delegate respondsToSelector:@selector(taskCellReceiveActionWithObject:)]) {
            [self.delegate taskCellReceiveActionWithObject:task];
        }
    }
}
@end
